home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / Velocity Engine / VelEng Wavelet / source / QTReadWriteJPEG.h < prev    next >
Encoding:
Text File  |  2000-09-28  |  5.3 KB  |  141 lines  |  [TEXT/CWIE]

  1. //////////
  2. //
  3. //    File:        QTReadWriteJPEG.h
  4. //
  5. //    Contains:    Sample code for compressing and decompressing JPEG images.
  6. //
  7. //    Copyright:    © 1996-1998 by Apple Computer, Inc., all rights reserved.
  8. //
  9. //    Change History (most recent first):
  10. //
  11. //       <1>         04/27/98    rtm        first file
  12. //       
  13. //////////
  14. /*
  15.     Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  16.                 ("Apple") in consideration of your agreement to the following terms, and your
  17.                 use, installation, modification or redistribution of this Apple software
  18.                 constitutes acceptance of these terms.  If you do not agree with these terms,
  19.                 please do not use, install, modify or redistribute this Apple software.
  20.  
  21.                 In consideration of your agreement to abide by the following terms, and subject
  22.                 to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  23.                 copyrights in this original Apple software (the "Apple Software"), to use,
  24.                 reproduce, modify and redistribute the Apple Software, with or without
  25.                 modifications, in source and/or binary forms; provided that if you redistribute
  26.                 the Apple Software in its entirety and without modifications, you must retain
  27.                 this notice and the following text and disclaimers in all such redistributions of
  28.                 the Apple Software.  Neither the name, trademarks, service marks or logos of
  29.                 Apple Computer, Inc. may be used to endorse or promote products derived from the
  30.                 Apple Software without specific prior written permission from Apple.  Except as
  31.                 expressly stated in this notice, no other rights or licenses, express or implied,
  32.                 are granted by Apple herein, including but not limited to any patent rights that
  33.                 may be infringed by your derivative works or by other works in which the Apple
  34.                 Software may be incorporated.
  35.  
  36.                 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  37.                 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  38.                 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39.                 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  40.                 COMBINATION WITH YOUR PRODUCTS.
  41.  
  42.                 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  43.                 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  44.                 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45.                 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  46.                 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  47.                 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  48.                 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. */
  50.  
  51. //////////
  52. //
  53. // header files
  54. //
  55. //////////
  56.  
  57. #include <FixMath.h>
  58. #include <ImageCompression.h>
  59. #include <Movies.h>
  60. #include <QuickTimeComponents.h>
  61. #include <StandardFile.h>
  62.  
  63.  
  64. #ifndef PASCAL_RTN    
  65. #define PASCAL_RTN pascal
  66. #endif
  67.  
  68.  
  69. //////////
  70. //
  71. // constants
  72. //
  73. //////////
  74.  
  75. #define kImageFileCreator        FOUR_CHAR_CODE('ogle')
  76. #define kBufferSize                codecMinimumDataSize        // data unload buffer size
  77.  
  78. #define kSaveImagePrompt        "Save compressed image as:"
  79. #define kSaveImageFileName        "Untitled.jpg"
  80. #define kWindowTitle            "Photo - JPEG"
  81.  
  82. // JFIF (JPEG) markers
  83. enum {
  84.     kSOFMarker                    = 0xC0,                        // start Of Frame N
  85.     kSOFMarker2                    = 0xC2,
  86.     kDHTMarker                    = 0xC4,                        // DHT Marker
  87.     kDACMarker                    = 0xCC,                        // DAC
  88.  
  89.     kRSTOMarker                    = 0xD0,                        // RSTO marker
  90.     kSOIMarker                    = 0xD8,                     // image start marker
  91.     kEOIMarker                    = 0xD9,                        // image end marker
  92.     kSOSMarker                    = 0xDA,                        // SOS marker
  93.     kDQTMarker                    = 0xDB,                        // DQT marker
  94.  
  95.     kAPPOMarker                    = 0xE0,                        // APPO marker
  96.     kCommentMarker                = 0xFE,                        // comment marker
  97.  
  98.     kStartMarker                = 0xFF                        // marker loacted after this byte
  99. };
  100.  
  101.  
  102. //////////
  103. //
  104. // data types
  105. //
  106. //////////
  107.  
  108. // a record to hold info about the JPEG data while we're loading it from disk
  109. struct DLDataRec
  110. {    
  111.     long                        fRefNum;                    // ref number of current file
  112.     long                        fFileLength;            
  113.     Ptr                            fOrigPtr;                    // address of start of buffer
  114.     Ptr                            fEndPtr;                    // address of end of buffer
  115. };
  116. typedef struct DLDataRec DLDataRec;
  117. typedef DLDataRec *DLDataPtr, **DLDataHnd;
  118.  
  119.  
  120. //////////
  121. //
  122. // function prototypes
  123. //
  124. //////////
  125.  
  126. void                            QTJPEG_PromptUserForJPEGFileAndDisplay (void);
  127. OSErr                            QTJPEG_ReadJPEG (FSSpec theFSSpec, CGrafPtr *theGWorld);
  128. OSErr                            QTJPEG_ConvertJPEG (Handle image, CGrafPtr *newWorld);
  129. OSErr                             QTJPEG_ReadJPEGHeader (short theRefNum, ImageDescriptionHandle theDesc, Rect *theRect);
  130. UInt8                            QTJPEG_FindNextMarker (long theRefNum);
  131. OSErr                             QTJPEG_HandleAPPOMarker (UInt8 theMarker, long theRefNum, ImageDescriptionHandle theDesc, Boolean *readingExtension);
  132. OSErr                             QTJPEG_HandleSOFMarker (long theRefNum, ImageDescriptionHandle theDesc, Boolean readingExtension);
  133. void                             QTJPEG_HandleSOSMarker (long theRefNum);
  134. UInt8                              QTJPEG_ReadByte (short theRefNum);
  135. UInt16                             QTJPEG_ReadWord (short theRefNum);
  136. void                             QTJPEG_SkipLength (long theRefNum);
  137. OSErr                             QTJPEG_NewJPEGWorld (GWorldPtr *theWorld, short theDepth, Rect theRect);
  138. OSErr                             QTJPEG_SaveJPEG (GWorldPtr theWorld);
  139. PASCAL_RTN OSErr                 QTJPEG_DataUnloadProc (Ptr theData, long theBytesNeeded, long theRefCon);
  140. PASCAL_RTN OSErr                 QTJPEG_DataLoadingProc (Ptr *theData, long theBytesNeeded, long theRefCon);
  141.